<%@ page language="java" pageEncoding="UTF-8" contentType="text/html;charset=utf-8"%>
<%@include file="/common/taglibs.jsp"%>
<html>
<head>
<%@include file="/common/scripts.jsp"%>
<script type="text/javascript">
$(function() {
  $("#theForm").validate({rules: {
      appItem : {
          required : true
      },
      appName : {
          required : true
      },
      adUrl : {
          required : true
      },       
      slogn : {
          required : true,
      },
      adDesc : {
          required : true
      },
      adType : {
          required : true
      },      
      imageFile : {
          required : {
              depends : function(element){
                  return $("#sysImage").val().length==0;
              }
          }
      }
	}});
});

$(function(){
    $("#saveBtn").click(function() {
        $('#theForm').ajaxSubmit({
            url : "<c:url value='save'/>",
            beforeSubmit : function() {
                var rtnVal = $("#theForm").valid();
                return rtnVal;
            },
            success : function(data, statusText, xhr, $form) {
                alert(data.message);
                if (data.success) {
                    var url = "edit?id=" + data.data;
                    window.location.href = url;
                }
            },
            dataType : 'json'
        });
    });
});

$(function(){
    $("#deleteBtn").click(function(){
        if (confirm("<fmt:message key='confirm.message.delete'/>")) {
    		$('#theForm').ajaxSubmit({
    			url:"delete",
    			success:function(data, statusText, xhr, $form){
    				alert(data.message);
    				if (data.success) {
    					window.location.href = "<c:url value='init'/>";
    				}
    			},
    			dataType:'json'
    		});    
        }
    });    
})
$(function(){
    $("[name=target]").click(function(){
        var val = $("[name=target]:checked").val();
        if (val=="appName"){
            $("#appName").show();
            $("#appPick").show();
            $("#adUrl").hide();
        } else {
            $("#appName").hide();
            $("#appPick").hide();
            $("#adUrl").show();
        }
    });    
    
   <c:if test="${appAdItem.adUrl==null}">
   $("#target1").prop("checked",true);
   $("#target1").click();
   </c:if>   
   <c:if test="${appAdItem.appItem ==null && appAdItem.adUrl != null}">
   $("#target2").prop("checked",true);
   $("#target2").click();
   </c:if>       
});
$(function(){
   $("#appPick").click(function(){
       openWin("<c:url value='/app/appItemPicker/init?callback=callback'/>",900,500);
   });
});
function callback(data) {
    $("#appName").val(data.appName);
}
</script>
</head>
<body>
  <div class="pageOuter">
    <div class="contentOuter">
      <div class="contentMultiColumn" style="width: 100%;">
        <div class="buttonBox_R">
          <a href="javascript:void(0);" id="saveBtn" class="css_btn"><img class="button save" src="<c:url value='/images/icon_transparent.png'/>" /> <fmt:message
              key='button.save' /></a>
          <c:if test="${appAdItem.id != null }">
            <a href="javascript:void(0);" id="deleteBtn" class="css_btn"><img class="button delete" src="<c:url value='/images/icon_transparent.png'/>" />
              <fmt:message key='button.delete' /></a></c:if>
          <a href="<c:url value='init'/>" class="css_btn"><img class="button back" src="<c:url value='/images/icon_transparent.png'/>" /> <fmt:message
              key='button.back.page' /></a>
        </div>
        <fieldset class="pageBlock">
          <legend><fmt:message key='label.appAdItem_edit.title2'/></legend>
          <div class="jqgrid-container">
            <form:form name="theForm" id="theForm" action="save" method="post" commandName="appAdItem" enctype="multipart/form-data">          
                    <form:hidden path="id" />
                    <table class="queryForm">
                        <tr>
                            <td width="8%"><span class="required">*</span>
                            <fmt:message key='bo.AppAdItem.slogn' />:</td>
                            <td width="35%"><form:input path="slogn" maxlength="100"  cssClass="required" cssStyle="width: 100%;" /></td>
                            <td width="8%"><span class="required">*</span>
                            <fmt:message key='bo.AppAdItem.adType' />:</td>
                            <td width="35%"><form:select path="adType">
                              <form:option value=""></form:option>
                              <form:option value="AD"><fmt:message key='bo.AppAdItem.adType.ad'/></form:option>
                              <form:option value="HOT"><fmt:message key='bo.AppAdItem.adType.hot'/></form:option>
                            </form:select></td>
                        </tr>
                        <tr>
                            <td width="8%"><span class="required">*</span>
                            <fmt:message key='bo.AppAdItem.adDesc' />:</td>
                            <td width="35%"><form:textarea path="adDesc" cssStyle="width:100%;" maxlength="255" rows="8" /></td>                        
                            <td width="8%"><span class="required">*</span>
                            <fmt:message key='bo.AppAdItem.image' />:</td>
                            <td width="35%"><input type="file" size="20" name="imageFile" style="width:70%"/>
                            <form:hidden path="sysImage"/>
                            <c:if test="${appAdItem.sysImage != null }">
                            <br></br>
                            <img width=114 height=112 src="<c:url value='/app/image/${appAdItem.sysImage.id}'/>">
                            </c:if></td>
                        </tr> 
                        <tr>
                            <td width="8%"><fmt:message key='bo.AppDevice.enable'/></td>
                            <td width="35%"><form:radiobutton path="enable" value="true"/><fmt:message key='bo.AppAdItem.enable.true' />
                            <form:radiobutton path="enable" value="false"/><fmt:message key='bo.AppAdItem.enable.false' /></td>
                            <td width="8%">&nbsp;</td>
                            <td width="35%">&nbsp;</td>
                        </tr>                        
                        <tr>
                            <td width="8%"><span class="required">*</span>
                            <fmt:message key='bo.AppAdItem.target'/>:</td>
                            <td width="35%" colspan="3">
                            <input type="radio" id="target1" name="target" value="appName"/><fmt:message key='bo.AppItem.appName' />
                            <input type="radio" id="target2" name="target" value="adUrl"/><fmt:message key='bo.AppAdItem.adUrl' />
                            <input type="text" name="appName" id="appName" value="${appAdItem.appItem.appName}" style="display:none;"><a class="css_imgBtn" id="appPick" href="javascript:void(0);" style="display:none;"><img height="20" class="button search" src="<c:url value='/images/icon_transparent.png'/>"></a>
                            <input type="text" name="adUrl" id="adUrl" value=" ${appAdItem.adUrl}" size="80" style="display:none;"></td>
                        </tr>                                                                
                    </table>
            </form:form>
          </div>
        </fieldset>
      </div>
    </div>
  </div>
</body>
<!--pageOuter end-->
</html>
